//
//  RFATextEditorController.m
//  RFA Manager
//
//  Created by Torsten Kammer on 28.02.08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "RFATextEditorController.h"
#import "RFAAttributedStringValueTransformer.h"

#import "RFATreeNode.h"
#import "PropertyCategories.h"

@implementation RFATextEditorController

+ (void)initialize
{
	static BOOL isInitialized = NO;
	if (isInitialized) return;
	isInitialized = YES;
	
	[NSValueTransformer setValueTransformer:[[RFAAttributedStringValueTransformer alloc] init] forName:@"RFAAttributedStringValueTransformer"];
}

- (id)initWithArchiveEntry:(RFATreeNode *)entry;
{
	if (![super initWithWindowNibName:@"TextEditing"]) return nil;
	self.archiveEntry = entry;
	
	return self;
}

@synthesize archiveEntry;

- (void)windowDidLoad
{
	textView.textStorage.font = [NSFont userFixedPitchFontOfSize:-1.0f]; // Will return default size
	[textView bind:@"attributedString" toObject:self withKeyPath:@"archiveEntry.contents" options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSContinuouslyUpdatesValueBindingOption, @"RFAAttributedStringValueTransformer", NSValueTransformerNameBindingOption, nil]];
}
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName;
{
	// It's got to be an em dash according to Apple HIG
	return [displayName stringByAppendingFormat:@" %C %@", 0x2014, archiveEntry.name];
}

- (NSUndoManager *)undoManagerForTextView:(NSTextView *)view
{
	return [self.document undoManager];
}

@end
